package com.ruoyi.project.im.kuaijie.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.im.kuaijie.domain.Kuaijie;
import com.ruoyi.project.im.kuaijie.service.IKuaijieService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 快捷语管理Controller
 *
 * @author ruoyi
 * @date 2022-09-11
 */
@Controller
@RequestMapping("/im/kuaijie")
public class KuaijieController extends BaseController
{
    private String prefix = "im/kuaijie";

    @Autowired
    private IKuaijieService kuaijieService;

    @RequiresPermissions("im:kuaijie:view")
    @GetMapping()
    public String kuaijie()
    {
        return prefix + "/kuaijie";
    }

    /**
     * 查询快捷语管理列表
     */
    @RequiresPermissions("im:kuaijie:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Kuaijie kuaijie) {
        startPage();
        List<Kuaijie> list = kuaijieService.selectKuaijieList(kuaijie);
        return getDataTable(list);
    }

    /**
     * 导出快捷语管理列表
     */
    @RequiresPermissions("im:kuaijie:export")
    @Log(title = "快捷语管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Kuaijie kuaijie)
    {
        List<Kuaijie> list = kuaijieService.selectKuaijieList(kuaijie);
        ExcelUtil<Kuaijie> util = new ExcelUtil<Kuaijie>(Kuaijie.class);
        return util.exportExcel(list, "快捷语管理数据");
    }

    /**
     * 新增快捷语管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存快捷语管理
     */
    @RequiresPermissions("im:kuaijie:add")
    @Log(title = "快捷语管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Kuaijie kuaijie)
    {
        return toAjax(kuaijieService.insertKuaijie(kuaijie));
    }

    /**
     * 修改快捷语管理
     */
    @RequiresPermissions("im:kuaijie:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Kuaijie kuaijie = kuaijieService.selectKuaijieById(id);
        mmap.put("kuaijie", kuaijie);
        return prefix + "/edit";
    }

    /**
     * 修改保存快捷语管理
     */
    @RequiresPermissions("im:kuaijie:edit")
    @Log(title = "快捷语管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Kuaijie kuaijie)
    {
        return toAjax(kuaijieService.updateKuaijie(kuaijie));
    }

    /**
     * 删除快捷语管理
     */
    @RequiresPermissions("im:kuaijie:remove")
    @Log(title = "快捷语管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kuaijieService.deleteKuaijieByIds(ids));
    }
}
